#!/usr/bin/python
###############################################################################
#Programmers:                                                                 #
#             Danil Dotsenko, dd@accentsolution.com                           #
#Date: 07/25/2006                                                             #
#Filename: miloCalendar.py                                                    #
#Version: 0.1                                                                 #
#                                                                             #
#                                                                             #
#       Copyleft 2006 Danil Dotsenko                                          #
#                                                                             #
#    This program is free software; you can redistribute it and/or modify     #
#    it under the terms of the GNU General Public License as published by     #
#    the Free Software Foundation; either version 2 of the License, or        #
#    (at your option) any later version.                                      #
#                                                                             #
#    This program is distributed in the hope that it will be useful,          #
#    but WITHOUT ANY WARRANTY; without even the implied warranty of           #
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            #
#    GNU General Public License for more details.                             #
#                                                                             #
#    You should have received a copy of the GNU General Public License        #
#    along with this program; if not, write to the Free Software              #
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA #
#                                                                             #
###############################################################################

'''
Notes:
- This is a centralized location for functions and methods digging through INI file and getting the options out in chronological order.
- These functions will populate the configuration array previously set up by the main code.
'''

import re
import os.path

# custom libraries contained in the same folder as this file.
import canvasclasses # these are canvas elements, particular to calendar UI.
import customdate # a very narow, custom selection of date-related functions: Today-related, weekday for any arbitrary date, 1st weekday and length of month.
from renderer import * # populates and renders the canvas. Will be a wraper for different rendering backends.

###########################################################################
# All applet settings go here, and are accessible from everywhere.
###########################################################################
class multiPurposeAsset:
	def __init__(self):
		self.base = None
		self.name = None
		self.path = None
		self.ptr = None
		self.version = None
		self.settings = None

class configuration:
	'''An all-encoupasing, application-wide configuration storage location. This is not a permanent file-based storage'''
	def __init__(self):
		self.name = "miloCalendar"
		self.version = "v0.6, June 17, 2006"
		self.author = "Danil (Suslik) Dotsenko (dd@accentsolution.com)"
		self.skin = multiPurposeAsset()
		self.skin.base = "./skins/default/" # always put in the ending slash!
		self.skin.path = "./skins/default/default.ini"
		self.skin.name = "default"
		self.skin.settings = {}
		self.home = multiPurposeAsset() # that is the top-level folder in which locale, temas and others reside.
		self.home.base = "" # putting in ./ may screw things up for now.
		self.locale = multiPurposeAsset() # po / mo files are there.
		self.calendardata = multiPurposeAsset() # this will hold the string with path of iCal file. See getConfigs bellow.
		# self.renderOrder = []
		# It contains the "normalized" string as key and "localized" as value.
		# example {'Background':'Rainlendar', 'Days':'Rainlendar', 'Today':'Rainlendar'}
		# canvas : all drawn elements will be buffered here... Err.. All elements mentioned here will be drawn.
		self.canvas = None
		self.today = customdate.now()

appConfig=configuration()



###################################################################
# *canvas* section
# Functions related to converting Rainlendar skin images into
#   images accetable for Karamba.
#
def prepareCanvas():
	'''
	This function only creates basic methods and classes of the canvas.
	Canvas
		Canvas variables
		Month array
			Month variables
			Day array
				Day variables
				Layer array (note, we dont add any layers here.

	All other manipulations on the canvas may occur regularly
	and are in separate functions.
	'''
	global appConfig

	##########
	# CANVAS
	appConfig.canvas=canvasclasses.canvasClass()
	##########
	##########
	# MONTHS
	# in future we need to figure out how to get how many month to draw and arrange.
	# i wish it was part of the skin options namespace
	# now,
	# Note - we are referring to the actual month full of dates, not the month name lable.
	# month name lable is handled as special element, among buttons etc.
	appConfig.canvas.month.append({})
	for monthnum in range(1,2):
		appConfig.canvas.month.append(canvasclasses.monthClass())
	# MONTHS
	##########
		##########
		# DAY
		appConfig.canvas.month[monthnum].day.append({'settingsgo':'here'})
		for daynum in range(1,32): # we are keeping day[0] for spare parts. rest match day numbers			# creating the day
			appConfig.canvas.month[monthnum].day.append(canvasclasses.dayClass())
		# all-in-all we get 32 days, with index ranging from [0] to [31]
		##########

# *canvas* section
###################################################################



def test(fileName):
	import compatlayer # very small image splitter. Rainlendar skins rely on images containing multiple UI pars. Karamba cant handle it.
	renderOrder, sectionDict = compatlayer.sectionOrder(fileName)
	import localconf # Very, very friendly ConfigParser wrapper.
	iniobj = localconf.cfgObject('./skins/default/default.ini')
	settings={}
	for section in renderOrder:
		settings[section]= compatlayer.sectionGet(section, sectionDict, iniobj), '\n'
	iniobj = None
	appConfig.skin.settings=settings
	print settings
	prepareCanvas()


if __name__ == '__main__':
	test(appConfig.skin.path)